package com.ruoyi.web.controller.phonecase;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.PcTemplate;
import com.ruoyi.system.service.IPcTemplateService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 模板Controller
 * 
 * @author ruoyi
 */
@RestController
@RequestMapping("/phonecase/template")
public class PcTemplateController extends BaseController
{
    @Autowired
    private IPcTemplateService pcTemplateService;

    /**
     * 查询模板列表
     */
    @PreAuthorize("@ss.hasPermi('phonecase:template:list')")
    @GetMapping("/list")
    public TableDataInfo list(PcTemplate pcTemplate)
    {
        startPage();
        List<PcTemplate> list = pcTemplateService.selectPcTemplateList(pcTemplate);
        return getDataTable(list);
    }

    /**
     * 导出模板列表
     */
    @PreAuthorize("@ss.hasPermi('phonecase:template:export')")
    @Log(title = "模板", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PcTemplate pcTemplate)
    {
        List<PcTemplate> list = pcTemplateService.selectPcTemplateList(pcTemplate);
        ExcelUtil<PcTemplate> util = new ExcelUtil<PcTemplate>(PcTemplate.class);
        util.exportExcel(response, list, "模板数据");
    }

    /**
     * 获取模板详细信息
     */
    @PreAuthorize("@ss.hasPermi('phonecase:template:query')")
    @GetMapping(value = "/{templateId}")
    public AjaxResult getInfo(@PathVariable("templateId") Long templateId)
    {
        return success(pcTemplateService.selectPcTemplateByTemplateId(templateId));
    }

    /**
     * 新增模板
     */
    @PreAuthorize("@ss.hasPermi('phonecase:template:add')")
    @Log(title = "模板", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PcTemplate pcTemplate)
    {
        pcTemplate.setCreateBy(getUsername());
        return toAjax(pcTemplateService.insertPcTemplate(pcTemplate));
    }

    /**
     * 修改模板
     */
    @PreAuthorize("@ss.hasPermi('phonecase:template:edit')")
    @Log(title = "模板", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PcTemplate pcTemplate)
    {
        pcTemplate.setUpdateBy(getUsername());
        return toAjax(pcTemplateService.updatePcTemplate(pcTemplate));
    }

    /**
     * 删除模板
     */
    @PreAuthorize("@ss.hasPermi('phonecase:template:remove')")
    @Log(title = "模板", businessType = BusinessType.DELETE)
    @DeleteMapping("/{templateIds}")
    public AjaxResult remove(@PathVariable Long[] templateIds)
    {
        return toAjax(pcTemplateService.deletePcTemplateByTemplateIds(templateIds));
    }
}

